<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>


<div id="form">
    <b>Filtr:</b><br>
    <form:form commandName="productFilter" method="post">
        <table>
            <tr><td class="label">Nazwa:</td><td> <form:input path="productName"/></td></tr>
        
        <tr><td class="label">Kategoria główna:</td><td>
        <form:select path="mainCategory">
              <form:option value="0" label="------"/>
             <c:forEach items="${categoryList}" var="cat">
                    <form:option value="${cat.idcategory}" label="${cat.categoryname}"/>
             </c:forEach>
        </form:select></td></tr>
        <tr><td class="label">Podkategoria:</td><td>
        <form:select path="subCategory">
             <form:option value="0" label="------"/>
             <c:forEach items="${subCategoryList}" var="cat">
                    <form:option value="${cat.idcategory}" label="${cat.categoryname}"/>
             </c:forEach>
             
        </form:select></td></tr>
        <tr><td class="label">Ilość wyników na stronie:</td><td>
            <form:select path="itemsOnPage">
             <form:option value="5" label="5"/>
             <form:option value="10" label="10"/>
             <form:option value="20" label="20"/>
             <form:option value="30" label="30"/>
             <form:option value="40" label="40"/>
             <form:option value="50" label="50"/>
            </form:select>
            </td></tr>
             <tr><td></td><td> <input type="submit" value="Filtruj"/></td></tr>
        </table>

    </form:form>
    </div>
    <a href="product.htm" style="margin-left : 120px"><img src="../img/icons/new.png" border="0" alt="Dodaj nowy produkt" ></a>
    <table>
        <tr><td class="header" width="350"><b>Nazwa produktu</b></td><td class="header" width="250"><b>Nazwa kategorii</b></td><td class="header" width="100"><b>Cena</b></td><td class="header"><b>Edytuj</b></td><td class="header"><b>Usuń</b></td></tr>
        <c:forEach items="${productList}" var="prod">
            <tr><td class="main_cat">${prod.productname}</td><td class="sub_cat" style="margin-left : 0px">${prod.category.categoryname}</td><td class="sub_cat" style="text-align : right">${prod.price} zł</td><td ><a href="product.htm?op=edit&id=${prod.idproduct}"><img src="../img/icons/edit1.png" border="0"/></a></td><td><a href="products.htm?op=delete&id=${prod.idproduct}"><img src="../img/icons/remove.png" border="0"/></a></td></tr>
        </c:forEach>
    </table>
    <div id="pagecount">
        <c:forEach var="page" begin="1" end="${pageCount}" step="1" varStatus ="status">
            <a href="products.htm?op=showPage&page=${page}&main=${productFilter.mainCategory}&sub=${productFilter.subCategory}&string=${productFilter.productName}&items=${productFilter.itemsOnPage}">${page}</a> &nbsp;
        </c:forEach>
    </div>